<!--#include file="functions.asp" -->
<%
'on error resume next
'set cn=Server.CreateObject("ADODB.Connection")
'cn.Open "MP2ENTTEST2", "MP2", "MP2"
dim sql
dim i
dim isUpdate
isUpdate="N"

'update exilinkrcp
if (request("isUC")="Y")and (request("status")="APPROVED W/O RECEIPT")then

    For i = 1 to CInt(request("Incr3"))-1
	  if (request("cb"&i)="Y")and(request("isEdit"&i)="Y") then
	    sql = "SELECT COUNT(*) FROM EXILINKRCP "
		sql = sql & "WHERE SEQNUM=" & request("seqnum") 
		sql = sql & "AND RECEIVERNUM='" & request("rn"&i) & "'"
		
		set rs=cn.execute(sql)
		if rs(0)=0 then
	  
	       	sql = "INSERT INTO EXILINKRCP (SEQNUM, PONUM, RECEIVERNUM)"
	    	sql = sql & " VALUES ("
	    	sql = sql & request("seqnum") & ",'"
	    	sql = sql & request("PONUM") & "','"
	    	sql = sql & request("rn"&i) & "')"
	    	cn.execute(sql)

	    	sql = "EXEC dbo.EXIPORECUPDATE "
	  		sql = sql & "@InvoiceStatus='" & request("status") & "',"
	  		sql = sql & "@InvoiceNum='" & request("InvoiceNo") & "',"
	  		sql = sql & "@InvoiceDate='" & request("InvRecDate") & "',"
	  		sql = sql & "@PONumber='" & request("PONum") & "',"
	  		sql = sql & "@ReceiverNum='" & request("rn"&i) & "'"
	  
	  		cn.execute(sql)
			isUpdate="Y"
		end if
		
	  End if
	Next
	
	if (isUpdate="Y") then
	sql = "UPDATE EXIREG SET INVSTATUS='APPROVED',"
	sql = sql & "SERVICERCP='Y', "
	sql = sql & "LOCATION='FINANCE' "
	sql = sql & " WHERE SEQNUM=" & request("seqnum")
	cn.execute(sql)
	
	sql = "INSERT INTO EXIHIST (SEQNUM,TRANSTYPE,LOCATION,DEPARTMENT,DATE,UPDATEUSER,UPDATESTAMP)"
  	sql = sql & " VALUES ("
  	sql = sql & request("seqnum") & ",'"
	sql = sql & "IUR','"
 	sql = sql & request("UC") & "','"
  	sql = sql & request("Dept") & "','"
  	sql = sql & request("RouteDate") & "','"
  	sql = sql & usrName & "',"
  	sql = sql & "GETDATE() )"
    cn.execute(sql)
	
	sql = "INSERT INTO EXIHIST (SEQNUM,TRANSTYPE,LOCATION,DEPARTMENT,DATE,UPDATEUSER,UPDATESTAMP)"
  	sql = sql & " VALUES ("
  	sql = sql & request("seqnum") & ",'"
	sql = sql & "IRT','"
 	sql = sql & request("recBy") & "','" '"FINANCE','"
  	sql = sql &  "FINANCE','"
  	sql = sql & request("RouteDate") & "','"
  	sql = sql & usrName & "',"
  	sql = sql & "GETDATE() )"
    cn.execute(sql)
	end if
end if

response.redirect "My_InvApproval.asp?seqnum="& request("seqnum")
%>